package conf

var NacosTpl = `
package conf

import (
    "encoding/json"
    "fmt"
    "github.com/nacos-group/nacos-sdk-go/v2/clients"
    "github.com/nacos-group/nacos-sdk-go/v2/common/constant"
    "github.com/nacos-group/nacos-sdk-go/v2/vo"
)

func NaCosInit() {
    clientConfig := constant.ClientConfig{
        NamespaceId:         Cfg.Nacos.NamespaceId,
        TimeoutMs:           5000,
        NotLoadCacheAtStart: true,
        LogDir:              "/tmp/nacos/log",
        CacheDir:            "/tmp/nacos/cache",
        LogLevel:            "debug",
    }
    serverConfigs := []constant.ServerConfig{
    {
        IpAddr:      Cfg.Nacos.Host,
        ContextPath: "/nacos",
        Port:        uint64(Cfg.Nacos.Port),
        Scheme:      "http",
        },
    }
    configClient, err := clients.CreateConfigClient(map[string]interface{}{
        "serverConfigs": serverConfigs,
        "clientConfig":  clientConfig,
    })
    if err != nil {
        panic(err)
    }
    content, err := configClient.GetConfig(vo.ConfigParam{
        DataId: Cfg.Nacos.DataId,
        Group:  Cfg.Nacos.Group,
    })
    if err != nil {
        panic(err)
    }
    err = json.Unmarshal([]byte(content), &Cfg)
    if err != nil {
        panic(err)
    }
    fmt.Println(Cfg)
}
`
